import { useEffect, useState, useRef } from 'react';
import { message, Modal } from 'antd';
import {
  ProFormText,
  ModalForm,
  ProFormSwitch,
  ProFormSelect,
  ProTable,
  ProColumns,
} from '@ant-design/pro-components';
import { isLocal, isSuccess } from '@/utils';
import { eidtPasswrodApi, rechargeApi, rechargeListApi } from '@/api';
import dayjs from 'dayjs';

export default function RechargeListModal({ open, setOpen, formData }: any) {
  console.log('formData: ', formData);

  // 请求
  const request = async (params: any) => {
    params.pageNum = params.current;
    params.userId = formData?.id;
    const res: any = await rechargeListApi(params);
    console.log('res:充值列表 ', res.data);
    if (!isSuccess(res)) return { data: [], total: 0 };
    return { data: res?.data?.list, total: res?.data?.total, success: true };
  };

  const columns: ProColumns[] = [
    {
      title: '充值金额(USDT)',
      dataIndex: 'money',

      render: (text: any) => <span className={` ${text < 0 ? 'color-green' : ''}`}>{text}</span>,
    },
    {
      title: '充值前余额',
      dataIndex: 'last',
    },
    {
      title: '充值后余额',
      dataIndex: 'afterMoney',
    },
    {
      title: '充值时间',
      dataIndex: 'create_time',
      hideInSearch: true,
      render: (text: any) => dayjs(text).format('YYYY-MM-DD HH:mm:ss'),
    },
  ];

  return (
    <Modal
      title={`账户明细: ${formData?.name}`}
      open={open}
      onClose={() => setOpen(false)}
      onCancel={() => setOpen(false)}
      onOk={() => setOpen(false)}
      width={800}
      height={900}
    >
      <br />
      <ProTable rowKey="id" columns={columns} request={request} search={false} options={false} />
    </Modal>
  );
}
